<?php
/**
 * news actions.
 *
 * @package    IPLIFE
 * @subpackage новости
 * @author     alexey.shapran@gmail.com
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class newsActions extends sfActions
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
		//Get general news list
		$this->pager = new sfDoctrinePager('News', sfConfig::get('app_max_per_page'));
		$query = Doctrine_Query::create()
			->from('news')
			->orderBy('updated_at DESC');
		$this->pager->setQuery($query);
		($request->getParameter('ukr',false))	?	$this->pager->setPage(1)
												:	$this->pager->setPage($request->getParameter('page', 1));
		$this->pager->init();

		//Get ukrainian news list
		$this->pager_ukr = new sfDoctrinePager('News', sfConfig::get('app_max_per_page'));
		$query = Doctrine_Query::create()
			->from('news')
			->where('news.is_ukraine=1')
			->orderBy('updated_at DESC');
		$this->pager_ukr->setQuery($query);
		(!$request->getParameter('ukr',false))	?	$this->pager_ukr->setPage(1)
												:	$this->pager_ukr->setPage($request->getParameter('page', 1));

		$this->pager_ukr->init();

		
		$response = $this->getResponse();		
		$response->addMeta('keywords', SettingsData::Get_it(SettingsData::NEWS_KEY));
		$response->addMeta('description', SettingsData::Get_it(SettingsData::NEWS_DESC));
		$response->setTitle(sfConfig::get('app_title')." | ".SettingsData::Get_it(SettingsData::NEWS_TITLE)  );
		
	}

	/**
	 * Get View of selected news
	 *
	 * @author	Alexey Shapran <alexey.shapran@gmail.com>
	 * @param sfRequest $request A request object
	 */
	public function executeView(sfWebRequest $request)
	{
		$this->news = $this->getRoute()->getObject();
		$this->forward404Unless($this->news);
		
		$response = $this->getResponse();
		$response->addMeta('keywords', $this->news['keywords']);
		$response->addMeta('description', $this->news['description']);
		$response->setTitle(sfConfig::get('app_title')." | ".$this->news['title']); 		
	}

	/**
	 * Get list of news by Tagname
	 *
	 * @author	Alexey Shapran <alexey.shapran@gmail.com>
	 * @param sfRequest $request A request object
	 */
	public function executeTags(sfWebRequest $request) 
	{
		$this->tag = rtrim(ltrim($request->getParameter('tag')));
		$this->forward404Unless($this->tag);

		$this->news = News::getByTag($this->tag);
	}
}
